package com.hhu.wangzb.shiro.jwt.payload;

import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.interfaces.Claim;

import java.util.Map;

/**
 * 用于对JWT中的负载(Claims)加载
 */
public interface ClaimsLoader {

    /**
     * 生成令牌时，加载负载
     * @param builder 使用builder.withClaim加载负载
     * 例：
     *     // User user = new User("a1", "lisi", "123456", 12);
     *
     *     builder
     *         .withClaim("userId", user.getUserId())
     *         .withClaim("username", user.getUsername())
     *         .withClaim("age", user.getAge());
     */
    default void load(JWTCreator.Builder builder) {
        // doNothing
    }

    /**
     * 将令牌中的负载加载到某个对象中
     * @param claimMap 存储负载的集合
     * 例：
     *       // User user1 = new User();
     *       user1.setUserId(claimMap.get("userId").asString());
     *       user1.setAge(claimMap.get("age").asInt());
     *       user1.setUsername(claimMap.get("username").asString());
     */
    default void reLoad(Map<String, Claim> claimMap) {
        // doNothing
    }
}
